﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：PurchaseOrderDetali.cs
    // 文件功能描述：采购单详情
    // 创建标识：吕海乐2009-04-10
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.ProcureManage
{
    public partial class PurchaseOrderDetali : BasePage
    {
        public PurchaseOrderDetali()
        {
            this.ModuleNo = Module.采购单管理.ToString();
        }

        IBLL_Purchase ip = Factory.BLL_Purchase();
        protected void Page_Load(object sender, EventArgs e)
        {
            //绑定采购单明细信息
            if (!IsPostBack)
            {
                string orderId = Request.QueryString["OrderID"];
                int totalCount = 0;
                Model.View.PurchaseOrder purchaseOrder = ip.GetPurchaseOrderByWhere(new HZ.DrugTrade.Model.Query.PurchaseOrder() { OrderID = orderId, SortFields = "PlanTime DESC" }, 1, 0, out totalCount)[0];
                txtAmount.Text = purchaseOrder.TotalAmount.ToString();
                txtHospital.Text = purchaseOrder.HospitalName;
                lblPurseOrder.Text = purchaseOrder.OrderName;
                SetBind();
            }
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }

        private void SetBind()
        {
            string orderId = Request.QueryString["OrderID"];
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            int totalCount = 0;
            IList<Model.View.PurchaseOrderDetail> purchaseOrderDetailList = ip.GetPurchaseOrderDetailByWhere(new HZ.DrugTrade.Model.Query.PurchaseOrderDetail() { OrderID = orderId, SortFields = "PlanTime DESC" }, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwPurseOrderDetail.PageSize = AspNetPager1.PageSize;
            gvwPurseOrderDetail.DataSource = purchaseOrderDetailList;
            gvwPurseOrderDetail.DataBind();
        }

        /// <summary>
        /// 绑定采购单状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwPurseOrderDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Literal ltlOrderDetailState = e.Row.FindControl("ltlOrderDetailState") as Literal;
                LinkButton lbnCheck = e.Row.FindControl("lbnCheck") as LinkButton;
                if (ltlOrderDetailState.Text == "0")
                {
                    ltlOrderDetailState.Text = "未确认";
                }
                else if (ltlOrderDetailState.Text == "1")
                {
                    ltlOrderDetailState.Text = "已提交";
                    lbnCheck.Enabled = false;
                }
                else if (ltlOrderDetailState.Text == "2")
                {
                    ltlOrderDetailState.Text = "已确认";
                    lbnCheck.Enabled = false;
                }
            }
        }

        /// <summary>
        /// 更改采购单状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwPurseOrderDetail_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "check")
            {
                string[] array = e.CommandArgument.ToString().Split(',');
                string orderDetailState = array[0];
                if (orderDetailState.Equals("0"))
                {
                    PurchaseOrderDetail orderDetail = new PurchaseOrderDetail();
                    orderDetail.OrderDetailID = array[1];
                    orderDetail.OrderID = Request.QueryString["OrderID"];
                    orderDetail.OrderDetailState = 1;
                    int flag = ip.UpdatePurchaseOrderDetail_OrderDetailState(orderDetail);
                    if (flag == 1)
                    {
                        PageInfo("该采购单已提交！", Request.RawUrl);
                    }
                    else
                    {
                        PageError("操作失败！", Request.RawUrl);
                    }
                }
                else
                {
                    PageError("无权进行此操作！", Request.RawUrl);
                }

            }
        }

        /// <summary>
        /// 批量提交审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string chkOrderDetail = Request["chkOrderDetail"];
            if (!string.IsNullOrEmpty(chkOrderDetail))
             {
                //批量更新函数
             }
        }
    }
}
